
import pygame
import sys
import random
pygame.init()
size=width,height=(600, 600)
bg_color=(89,230,180)
poses=[[300,0]]
rect = [300, 450, 80,30]
speed = 1
screen=pygame.display.set_mode(size)
clock = pygame.time.Clock()

pygame.time.set_timer(10,1000)
while 1:
    for event in pygame.event.get():
        if event.type==pygame.QUIT:
            sys.exit()
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                if rect[0]>10:
                    rect[0]-=20
            elif event.key == pygame.K_RIGHT:
                if rect[0]+80<width:
                    rect[0]+=20
        elif event.type == 10:
            poses.append([random.randint(10, width - 10), 0])

    screen.fill(bg_color)
    pygame.draw.rect(screen, (0, 255,0), rect)
    i=0
    while i < len(poses):
        pos = poses[i]
        pygame.draw.circle(screen,(255,0,0),pos,10)
        if pos[1]>height:
            poses.pop(i)
            continue
        pos[1]+=speed
        i+=1
    clock.tick(200)
    pygame.display.update()
